package com.smartstate.EMS.schedul;

import com.smartstate.EMS.config.mq.MessageProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeoutException;

/**
 * 定时服务
 */
@Configuration
@EnableScheduling
@Slf4j
public class StaticScheduleTask {
  @Resource
  MessageProducer messageProducer;

  @Scheduled(cron = "0 * * * * ?")
  private void CurrentTime() throws IOException, TimeoutException {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
    messageProducer.publish(df.format(new Date()));
    System.out.println("rabbitmq推送:"+df.format(new Date()));
  }
}
